﻿using IOA.MES.Business;
using IOA.MES.PdaApi.Models.Request.Product;
using IOA.MES.PdaApi.Models.Response.Product;
using System.Linq;
using System.Web.Http;

namespace IOA.MES.PdaApi.Controllers
{
    /// <summary>
    /// 组件管理
    /// </summary>
    public class ProductController : ApiController
    {
        /// <summary>
        /// 获取打包对象
        /// </summary>
        [HttpPost]
        public ResultJson<GetPackResponse> GetPack([FromBody] GetPackRequest request)
        {
            var pack = new WorkOrderMgr().GetPack(request.PackNo);
            return new ResultJson<GetPackResponse>(new GetPackResponse
            {
                Pack = pack == null ? null : new PackItem
                {
                    PackNo = pack.PackNo,
                    PackBatchNo = pack.PackBatchNo,
                    Quantity = pack.Products.Count,
                    ProductCode = pack.Products.FirstOrDefault()?.ProductCode,
                    ProductName = pack.Products.FirstOrDefault()?.ProductName,
                    OrderNo = pack.OrderNo,
                    WorkOrderNo = pack.WorkOrderNo
                }
            });
        }
    }
}
